package cn.bonoon.controllers.fmm;

import java.util.Date;

import cn.bonoon.core.IOwnerEditor;
import cn.bonoon.entities.RoleEntity;
import cn.bonoon.kernel.annotations.Transform;
import cn.bonoon.kernel.annotations.TransformField;
import cn.bonoon.kernel.annotations.Unique;
import cn.bonoon.kernel.annotations.WriteModel;
import cn.bonoon.kernel.util.BoolType;
import cn.bonoon.kernel.web.annotations.AutoDataLoader;
import cn.bonoon.kernel.web.annotations.components.AsCheckbox;
import cn.bonoon.kernel.web.annotations.components.AsComboBox;
import cn.bonoon.kernel.web.annotations.components.AsDateBox;
import cn.bonoon.kernel.web.annotations.components.AsPassword;
import cn.bonoon.kernel.web.annotations.components.AsSelector;
import cn.bonoon.kernel.web.annotations.components.ComboMultipleChecker;
import cn.bonoon.kernel.web.annotations.form.FormInsert;
import cn.bonoon.kernel.web.annotations.form.PropertyEditor;
import cn.bonoon.kernel.web.annotations.form.PropertyHelper;
import cn.bonoon.kernel.web.annotations.form.PropertyInsert;

@Transform
@FormInsert(2)
public class OwnerInsert extends OwnerEditor implements IOwnerEditor/*, DialogFormInitializer<OwnerEntity>*/ {

	private static final long serialVersionUID = 7967291434910414518L;

	@TransformField(writable = WriteModel.INSERTONLY)
	@PropertyInsert(required = BoolType.TRUE, value = 1)
	@Unique
	private String loginName;

	@TransformField(readable = false, writable = WriteModel.NONE)
	@PropertyInsert(value = 2, name = "密码", required = BoolType.TRUE)
	@AsPassword
	private String loginPwd;

	@TransformField(readable = false, writable = WriteModel.NONE)
	@PropertyInsert(value = 3, name = "确认密码", required = BoolType.TRUE)
	@AsPassword
	private String confimPwd;

	@PropertyEditor(value = 4)
	@AsSelector
	private Integer status;

	@PropertyEditor(5)
	@PropertyHelper("如果被强制修改密码，则用户在下次登录的时候会被要求修改密码，如果不修改密码，则无法正常登录系统")
	@AsCheckbox("是")
	private boolean forcedChangePwd;

	@PropertyEditor(6)
	@AsDateBox
	private Date expiredAt;
	
	@PropertyInsert(name = "角色", value = 7)
	@ComboMultipleChecker
	@AsComboBox
	@AutoDataLoader(RoleEntity.class)
	private Long[] roles;

	@PropertyInsert(name = "权限", value = 8, colspan = 1)
	@AsSelector(modelOptions = "privilege", title = "", comboBox = true, multiple = true)
	private String[] privilege;
	
//	@Override
//	public Object init(IService<OwnerEntity> is, DialogModel model, DialogEvent event, Long id, Object form) {
//		StringBuilder html = new StringBuilder();
//		ChannelInfo channelInfo = moduleManager.getChannelManager();
//		for (MenuInfo menu : channelInfo.getMenus()) {
//			html.append("<option value='").append(menu.getId()).append("'>").append(menu.getName()).append("</option>");
//		}
//		model.addObject("privilege", html);
//		return form;
//	}
	
	public String getLoginName() {
		return loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}

	public String getLoginPwd() {
		return loginPwd;
	}

	public void setLoginPwd(String loginPwd) {
		this.loginPwd = loginPwd;
	}

	public String getConfimPwd() {
		return confimPwd;
	}

	public void setConfimPwd(String confimPwd) {
		this.confimPwd = confimPwd;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public boolean isForcedChangePwd() {
		return forcedChangePwd;
	}

	public void setForcedChangePwd(boolean forcedChangePwd) {
		this.forcedChangePwd = forcedChangePwd;
	}

	public Date getExpiredAt() {
		return expiredAt;
	}

	public void setExpiredAt(Date expiredAt) {
		this.expiredAt = expiredAt;
	}

	public Long[] getRoles() {
		return roles;
	}

	public void setRoles(Long[] roles) {
		this.roles = roles;
	}

	public String[] getPrivilege() {
		return privilege;
	}

	public void setPrivilege(String[] privilege) {
		this.privilege = privilege;
	}

}
